package com.babo72.android_test;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.babo72.android_test.task.LookupRunningTask;
import com.babo72.android_test.webview.WebviewSSLActivity;
import com.babo72.android_test.xml.XmlParsing;

public class MainActivity extends Activity {
	
	private static final Class[] activities = {
		WebviewSSLActivity.class, XmlParsing.class, DrawableFromURL.class, SmsSend.class,
		LookupRunningTask.class
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		ListView listView = (ListView) findViewById(R.id.ListView01);

		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, activityNames());
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				Intent intent = new Intent(parent.getContext(), activities[position]);
				startActivity(intent);
			}
		});
		
		printDeviceInfo();
	}
	
	private void printDeviceInfo() {
		TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); 
		String imsi = mTelephonyMgr.getSubscriberId(); 
		String imei = mTelephonyMgr.getDeviceId(); 
		String phoneNumber = mTelephonyMgr.getLine1Number();
		
		Log.d(getClass().getSimpleName(), "imsi: " + imsi);
		Log.d(getClass().getSimpleName(), "imei: " + imei);
		Log.d(getClass().getSimpleName(), "phoneNumber: " + phoneNumber);
	}

    private String[] activityNames() {
    	String[] strs = new String[activities.length];
    	for(int i = 0; i < activities.length; i++) {
    		strs[i] = activities[i].getSimpleName();
    	}
    	
    	return strs;
    }

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
